package org.chickymate.client.view.panel;

import org.chickymate.client.HtmlConstants;
import org.chickymate.client.model.CommentDTO;
import org.chickymate.client.model.ModelDTO;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class CommentView extends AbstractModelView {
	
	public CommentView(ModelDTO model) {
		super(model);
	}

	@Override
	protected Widget getContent(ModelDTO model) {
		CommentDTO comment = getComment(model);
		
		FlowPanel panel = new FlowPanel();
		Label text = new Label(comment.getText());
		text.setStyleName(HtmlConstants.COMMENT_TEXT_STYLE_NAME);
		
		panel.add(text);
		panel.add(createUrlAnchor(comment.getUrl()));
		return panel;
	}

	@Override
	protected String getDateContent(ModelDTO model) {
		return DateTimeFormat.getMediumDateTimeFormat().format(getComment(model).getCreatedDate());
	}
	
	private CommentDTO getComment(ModelDTO model) {
		return (CommentDTO)model;
	}

}
